package com.wgj.android.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wgj.android.R;
import com.wgj.android.events.Adver;
import com.wgj.android.events.ViedoEvent;
import com.wgj.android.tools.MyJZVideoPlayerStandard;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;

/**
 * Created by Administrator on 2018/2/3.
 */

public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.ViewHolder> implements View.OnClickListener {
    private Context mContext;
    private List<Adver> advers= new ArrayList<>();
    public  VideoAdapter(Context context){
        mContext=context;

    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.adver_video_item,parent,false);
        view.setOnClickListener(this);
        return  new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.player_list_video.setUp(
                advers.get(position).getViedoUrl(), JZVideoPlayer.SCREEN_WINDOW_LIST,
                advers.get(position).getTitle());
        Glide.with(mContext).load(advers.get(position).getThumbnail()).into(holder.player_list_video.thumbImageView);
        if( advers.get(position).getIs_get()==0){
            holder.tag.setBackgroundResource(R.drawable.adver_select_tag);
            holder.tag.setText("红包");

        }else {
            holder.tag.setBackgroundResource(R.drawable.adver_no_tag);
            holder.tag.setText("已领取");
        }

        EventBus.getDefault().postSticky(new ViedoEvent(advers.get(position).getType(), advers.get(position).getId()));
    }

    @Override
    public int getItemCount() {
        return advers.size();
    }

    @Override
    public void onClick(View v) {

    }
    class  ViewHolder extends  RecyclerView.ViewHolder {
        private MyJZVideoPlayerStandard player_list_video;
        private  TextView tag;
        public ViewHolder(View itemView) {
            super(itemView);
            player_list_video=itemView.findViewById(R.id.player_list_video);
            tag=itemView.findViewById(R.id.tag);
        }
    }
    public  void update(List<Adver> advers){
        this.advers=advers;
        notifyDataSetChanged();
    }
}
